//
//  VisitorLoginView.swift
//  SinaWeibo
//
//  Created by NeXTSTEP on 15/9/30.
//  Copyright © 2015年 NeXTSTEP. All rights reserved.
//

import UIKit

//使用协议传递点击事件
protocol VistorLoginViewDelegate : NSObjectProtocol {
    //登录按钮的协议方法
    
    func loginBtnDidClick()
    //注册按钮的协议方法
    func registerBtnDidClick()
}



class VisitorLoginView: UIView {
    
    //协议属性   一定要使用weak
    weak var vistorViewDelegate: VistorLoginViewDelegate?
    
    //需要变化的icon
    @IBOutlet weak var iconView: UIImageView!
    
    
    //首页转动的小房子   关联为了显示和隐藏
    @IBOutlet weak var smallIconView: UIImageView!
    
    //提示信息
    @IBOutlet weak var tipLabel: UILabel!
    
    //设置未登录页面的详细信息
    func setUpWithInfo(tipText: String,iconName: String,isHome: Bool = false) {
        self.tipLabel.text = tipText
        self.iconView.image = UIImage(named: iconName)
        self.smallIconView.hidden = !isHome
        if isHome {
            startAnimation()
        }
    }
    
    
    //圆圈小icon转圈圈
    private func startAnimation(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.repeatCount = MAXFLOAT
        anim.duration = 15.0
        anim.toValue = 2 * M_PI
        anim.removedOnCompletion = false
        smallIconView.layer.addAnimation(anim, forKey: nil)
    }
    
    //注册
    @IBAction func registerAction() {
        
        vistorViewDelegate?.registerBtnDidClick()
    }
    
    //登录
    @IBAction func loginAction() {
        
        vistorViewDelegate?.loginBtnDidClick()
    }
    
    
}
